package com.thouiot.modbus.enums;

/**
 * @description 寄存器类型枚举
 * @author wangkai
 * @date 2025/04/14 11:19
 */
public enum RegisterTypeEnum {
    // 对应 0区，可读可写布尔量
    COIL_INPUT("coil_input", "线圈", 0),
    // 对应 1区，只读布尔量
    DISCRETE_INPUT("discrete_input", "离散输入", 1),
    // 对应 3区，可读可写寄存器
    HOLDING_REGISTER("holding_register", "保持寄存器", 3),
    // 对应 4区，只读寄存器
    INPUT_REGISTER("input_register", "输入寄存器", 4);

    private final String code;
    private final String name;

    private final Integer range;

    RegisterTypeEnum(String code, String name, Integer range) {
        this.code = code;
        this.name = name;
        this.range = range;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public Integer getRange() {
        return range;
    }

    public static RegisterTypeEnum getRegisterTypeEnum(String code) {
        for (RegisterTypeEnum registerTypeEnum : RegisterTypeEnum.values()) {
            if (registerTypeEnum.getCode().equals(code)) {
                return registerTypeEnum;
            }
        }
        return null;
    }
}
